import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt

(_, _), (test_image, test_label) = tf.keras.datasets.cifar10.load_data()
test_image = test_image / 255.0
class_label = ['airplane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
plt.figure(figsize=(8, 4))  # 设置画布的大小
for i in range(21):
    plt.subplot(3, 7, i + 1)
    plt.axis('off')
    plt.title(class_label[test_label[i][0]])
    plt.imshow(test_image[i], cmap='viridis')
model = tf.keras.models.load_model("po2/znxlsj001.h5")


def predict_fun(img):
    img = tf.expand_dims(img, 0)
    prediction = model.predict(img)
    return prediction[0]


for img_idx in [33, 333, 3333]:
    y = predict_fun(test_image[img_idx])
    predicted_class = np.argmax(y)
    print(f"图像 {img_idx} 的预测结果: {class_label[predicted_class]}")

